SOURCE = $(wildcard *.c)
# The object files have the same name as source files,
# except for the file extension .c, which is replaced with
# .o.
OBJECT := $(SOURCE:.c=.o)
SHARED_LIBRARY := libsimplemath.so
# Define a conventional variable to specify the C compiler
# (CC).
CC=gcc
# no linker flags yet
# LDFLAGS = ...

# Define C compiler flags.

# -Wall: show all warnings
# -Wextra: show even more warnings
# -g: something with being able to debug
# -H: shows linked files when linking
# -fpic: has to compile as "position independent code" (PIC) for later creation of a shared library
CFLAGS= -Wall -Wextra -g -H -fpic

# Write to file `simple-math` the result of the linking of
# the object files.
simple_math: $(OBJECT)
	# $@ contains the target of the rule
	# $^ contains the dependencies of the rule
	# -o specifies the output file of linking the object files
	$(CC) $(CFLAGS) -o $@ $^

# Create a shared library from the simple_math code.
simple_math_shared_library: simple_math
	$(CC) -shared -o $(SHARED_LIBRARY) simple_math.o

all: simple_math
.PHONY: clean simple_math
clean:
	rm --verbose --force $(OBJECT) $(SHARED_LIBRARY) simple_math
